﻿using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Domain;
using Warehouse.Domain.DTO;
using Warehouse.Read.API.Applcation.Command.MovelibraryCommand;
using Warehouse.Read.API.Dtos;

namespace Warehouse.Read.API.Controllers
{
    /// <summary>
    /// 移库控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MovelibraryReadController : ControllerBase
    {
        private readonly IMediator _mediator;

        public MovelibraryReadController(IMediator mediator)
        {
            this._mediator = mediator;
        }
        /// <summary>
        /// 显示移库信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<MovelibraryMoveProductDTO>>> GetMovelibrary([FromQuery]SelectMovelibraryCommand command)
        {
            ApiResult<PageDTO<MovelibraryMoveProductDTO>> result = new ApiResult<PageDTO<MovelibraryMoveProductDTO>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填移库信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<MovelibraryFanDTO>>> GetMovelibraryById([FromQuery] FanMovelibraryCommand command)
        {
            ApiResult<List<MovelibraryFanDTO>> result = new ApiResult<List<MovelibraryFanDTO>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
    }
}
